/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * WeatherStationScreen.java
 *
 * Created on Feb 4, 2012, 10:49:52 AM
 */

package UI;

import DTO.ControlDTO;
import DTO.PacketDTO;

/**
 *
 * @author Administrator
 */
public class WeatherStationScreen extends javax.swing.JFrame {

    private String permission;
    private ControlDTO _operationWS;
    private ControlDTO _operationAS;
    //private PacketDTO _hourlyReport;

    /** Creates new form WeatherStationScreen */
    //public WeatherStationScreen(String permission, PacketDTO _hourlyReport, ControlDTO _operationWS, ControlDTO _operationAS) {
    public WeatherStationScreen(String permission, ControlDTO _operationWS, ControlDTO _operationAS) {
        this.permission = permission;
        this._operationWS = _operationWS;
        this._operationAS = _operationAS;
        //this._hourlyReport = _hourlyReport;
        initComponents();
        setPermission();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        wsPanel = new javax.swing.JPanel();
        turnOnWS = new javax.swing.JButton();
        turnOffWS = new javax.swing.JButton();
        asPanel = new javax.swing.JPanel();
        turnOnAS = new javax.swing.JButton();
        turnOffAS = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        emergency = new javax.swing.JButton();
        ac = new javax.swing.JPanel();
        installReportAnalyst = new javax.swing.JButton();
        sensors = new javax.swing.JPanel();
        installWeatherSystem = new javax.swing.JButton();
        report = new javax.swing.JPanel();
        viewCurrentWeather = new javax.swing.JButton();
        viewReport = new javax.swing.JButton();
        system = new javax.swing.JPanel();
        logout = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        wsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Weather System"))));

        turnOnWS.setText("Turn On");
        turnOnWS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                turnOnWSActionPerformed(evt);
            }
        });

        turnOffWS.setText("Turn Off");
        turnOffWS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                turnOffWSActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout wsPanelLayout = new javax.swing.GroupLayout(wsPanel);
        wsPanel.setLayout(wsPanelLayout);
        wsPanelLayout.setHorizontalGroup(
            wsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(wsPanelLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(wsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(turnOnWS)
                    .addComponent(turnOffWS))
                .addContainerGap(136, Short.MAX_VALUE))
        );
        wsPanelLayout.setVerticalGroup(
            wsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, wsPanelLayout.createSequentialGroup()
                .addComponent(turnOnWS)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(turnOffWS))
        );

        asPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Alarm System"));

        turnOnAS.setText("Turn on");
        turnOnAS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                turnOnASActionPerformed(evt);
            }
        });

        turnOffAS.setText("Turn Off");
        turnOffAS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                turnOffASActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 88, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 91, Short.MAX_VALUE)
        );

        emergency.setText("Emergency");

        javax.swing.GroupLayout asPanelLayout = new javax.swing.GroupLayout(asPanel);
        asPanel.setLayout(asPanelLayout);
        asPanelLayout.setHorizontalGroup(
            asPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(asPanelLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(asPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(turnOnAS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(turnOffAS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(emergency, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(26, 26, 26)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        asPanelLayout.setVerticalGroup(
            asPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(asPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(asPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, asPanelLayout.createSequentialGroup()
                        .addComponent(turnOnAS)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(turnOffAS)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(emergency)))
                .addGap(9, 9, 9))
        );

        ac.setBorder(javax.swing.BorderFactory.createTitledBorder("Admin Center"));

        installReportAnalyst.setText("Install report analyst");

        javax.swing.GroupLayout acLayout = new javax.swing.GroupLayout(ac);
        ac.setLayout(acLayout);
        acLayout.setHorizontalGroup(
            acLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(acLayout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(installReportAnalyst)
                .addContainerGap(82, Short.MAX_VALUE))
        );
        acLayout.setVerticalGroup(
            acLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(acLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(installReportAnalyst)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        sensors.setBorder(javax.swing.BorderFactory.createTitledBorder("Sensors"));

        installWeatherSystem.setText("Install weather system");

        javax.swing.GroupLayout sensorsLayout = new javax.swing.GroupLayout(sensors);
        sensors.setLayout(sensorsLayout);
        sensorsLayout.setHorizontalGroup(
            sensorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sensorsLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(installWeatherSystem)
                .addContainerGap(57, Short.MAX_VALUE))
        );
        sensorsLayout.setVerticalGroup(
            sensorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sensorsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(installWeatherSystem)
                .addContainerGap(34, Short.MAX_VALUE))
        );

        report.setBorder(javax.swing.BorderFactory.createTitledBorder("Report"));

        viewCurrentWeather.setText("View current weather");
        viewCurrentWeather.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewCurrentWeatherActionPerformed(evt);
            }
        });

        viewReport.setText("View report");

        javax.swing.GroupLayout reportLayout = new javax.swing.GroupLayout(report);
        report.setLayout(reportLayout);
        reportLayout.setHorizontalGroup(
            reportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(reportLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(reportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(viewReport)
                    .addComponent(viewCurrentWeather))
                .addContainerGap(59, Short.MAX_VALUE))
        );
        reportLayout.setVerticalGroup(
            reportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(reportLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(viewCurrentWeather)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(viewReport)
                .addContainerGap(43, Short.MAX_VALUE))
        );

        system.setBorder(javax.swing.BorderFactory.createTitledBorder("System"));

        logout.setText("Logout");
        logout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout systemLayout = new javax.swing.GroupLayout(system);
        system.setLayout(systemLayout);
        systemLayout.setHorizontalGroup(
            systemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(systemLayout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(logout)
                .addContainerGap(126, Short.MAX_VALUE))
        );
        systemLayout.setVerticalGroup(
            systemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(systemLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(logout)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ac, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(asPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(wsPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(report, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(sensors, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(system, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sensors, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(wsPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(asPanel, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(report, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(system, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(ac, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(21, 21, 21))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void viewCurrentWeatherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewCurrentWeatherActionPerformed
        /*java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ChooseLocationTypeWeatherScreen().setVisible(true);
            }
        });*/
//        new ChooseLocationTypeWeatherScreen(this._hourlyReport).setVisible(true);
    }//GEN-LAST:event_viewCurrentWeatherActionPerformed

    private void logoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutActionPerformed
        permission = null;
        this.dispose();
//        new MainScreen(this._hourlyReport, this._operationAS, this._operationWS).setVisible(true);
    }//GEN-LAST:event_logoutActionPerformed

    private void turnOnWSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_turnOnWSActionPerformed
        this._operationWS.setFlag(true);
    }//GEN-LAST:event_turnOnWSActionPerformed

    private void turnOffWSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_turnOffWSActionPerformed
        this._operationWS.setFlag(false);
    }//GEN-LAST:event_turnOffWSActionPerformed

    private void turnOnASActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_turnOnASActionPerformed
        this._operationAS.setFlag(true);
    }//GEN-LAST:event_turnOnASActionPerformed

    private void turnOffASActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_turnOffASActionPerformed
        this._operationAS.setFlag(false);
    }//GEN-LAST:event_turnOffASActionPerformed

    public void setPermission(){
        System.out.println("permission : " + permission);
        if (permission.equals("user")){
            turnOnAS.setEnabled(false);
            turnOffAS.setEnabled(false);
            turnOnWS.setEnabled(false);
            turnOffWS.setEnabled(false);
            installReportAnalyst.setEnabled(false);
            installWeatherSystem.setEnabled(false);
            emergency.setEnabled(false);
        }
    }
    
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
//                new WeatherStationScreen("admin").setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ac;
    private javax.swing.JPanel asPanel;
    private javax.swing.JButton emergency;
    private javax.swing.JButton installReportAnalyst;
    private javax.swing.JButton installWeatherSystem;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton logout;
    private javax.swing.JPanel report;
    private javax.swing.JPanel sensors;
    private javax.swing.JPanel system;
    private javax.swing.JButton turnOffAS;
    private javax.swing.JButton turnOffWS;
    private javax.swing.JButton turnOnAS;
    private javax.swing.JButton turnOnWS;
    private javax.swing.JButton viewCurrentWeather;
    private javax.swing.JButton viewReport;
    private javax.swing.JPanel wsPanel;
    // End of variables declaration//GEN-END:variables

}
